﻿/*
 * @author: wizardc
 */

using UnityEngine;

namespace Dou.Utils
{
    /// <summary>
    /// 贝塞尔曲线工具类
    /// </summary>
    public static class BezierUtil
    {
        /// <summary>
        /// 二次贝塞尔曲线
        /// </summary>
        public static Vector3 Quad(Vector3 startPoint, Vector3 controllerPoint, Vector3 endPoint, float percent)
        {
            return (1 - percent) * ((1 - percent) * startPoint + percent * controllerPoint) + percent * ((1 - percent) * controllerPoint + percent * endPoint);
        }

        /// <summary>
        /// 三次贝塞尔曲线
        /// </summary>
        public static Vector3 Cubic(Vector3 startPoint, Vector3 controllerPoint1, Vector3 controllerPoint2, Vector3 endPoint, float percent)
        {
            return (1 - percent) * ((1 - percent) * ((1 - percent) * startPoint + percent * controllerPoint1) + percent * ((1 - percent) * controllerPoint1 + percent * controllerPoint2)) + percent * ((1 - percent) * ((1 - percent) * controllerPoint1 + percent * controllerPoint2) + percent * ((1 - percent) * controllerPoint2 + percent * endPoint));
        }
    }
}
